home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / Gfx4PCQ.lha / WindowLib / Examples / CopperHammer / CopperHammer.p < prev    next >
Encoding:
Text File  |  1997-07-19  |  3.9 KB  |  210 lines

  1. PROGRAM CopperHammer;
  2. { A sample source for using user copper lists with PCQ and windowlib
  3.   © 1997 THOR-Software }
  4.  
  5. {$I "Include:utils/windowlib.i"}
  6. {$I "Include:utils/random.i"}
  7.     
  8. VAR
  9.     screen        :    ScreenPtr;
  10.     window        :    WindowPtr;
  11.     cop        :    Array [0..255] of SHORT; { will contain our "copper list" }
  12.     s        :    Integer;
  13.  
  14.  
  15. { draw a line in a given color, increments the position }
  16. PROCEDURE lin(col : Integer;VAR x : Integer);
  17. BEGIN
  18.     Color(window,col);
  19.     Line(window,x,0,x,255);
  20.     x:=x+1;
  21. END;
  22.  
  23. { calculate the next color for a pipe }
  24. FUNCTION sub(col,ad : Integer) : Integer;
  25. VAR
  26.     d        :    Integer;
  27. BEGIN
  28.     d:=15-ABS(ad-15);
  29.     d:=d-col;
  30.     IF d<0 THEN
  31.         d:=0;
  32.     sub:=d;
  33. END;
  34.  
  35. { draw a vertical pipe using HAM colors }
  36. PROCEDURE Vertical2;
  37. VAR
  38.     co1,co2        :    Integer;
  39.     c1,c2        :    Integer;
  40.     f1,f2        :    Integer;
  41.     x        :    Integer;
  42.     i        :    Integer;
  43. BEGIN
  44.     REPEAT
  45.         co1:=RangeRandom(2)*16+16;
  46.         co2:=RangeRandom(2)*16+16;
  47.     UNTIL co1<>co2;
  48.     f1:=RangeRandom(7);
  49.     f2:=RangeRandom(7);
  50.     x:=RangeRandom(319);
  51.     lin(5,x);
  52.     IF s=1 THEN BEGIN
  53.         FOR i:=0 TO 30 DO BEGIN
  54.             c1:=sub(f1,i);
  55.             c2:=sub(f2,i);
  56.             IF c1+c2>0 THEN BEGIN
  57.                 lin(c1+co1,x);
  58.                 lin(c2+co2,x)
  59.             END
  60.         END
  61.     END ELSE BEGIN
  62.         FOR i:=0 TO 15 DO BEGIN
  63.             c1:=sub(f1,i*2);
  64.             c2:=sub(f2,i*2);
  65.             IF c1+c2>0 THEN BEGIN
  66.                 lin(c1+co1,x);
  67.                 lin(c2+co2,x);
  68.             END
  69.         END
  70.     END;
  71.     lin(5,x);
  72. END;
  73.  
  74. { another pipe drawer, using only one color }
  75. PROCEDURE Vertical;
  76. VAR
  77.     c,co        :    Integer;
  78.     x        :    Integer;
  79.     f1        :    Integer;
  80.     i        :    Integer;
  81. BEGIN    
  82.     co:=RangeRandom(2)*16+16;
  83.     x:=RangeRandom(319);
  84.     f1:=RangeRandom(7);
  85.     lin(5,x);
  86.     IF s=1 THEN BEGIN
  87.         FOR i:=0 TO 30 DO BEGIN
  88.             c:=sub(f1,i);
  89.             IF c>0 THEN
  90.                 lin(c+co,x)
  91.         END
  92.     END ELSE BEGIN
  93.         FOR i:=0 TO 15 DO BEGIN
  94.             c:=sub(f1,i*2);
  95.             IF c>0 THEN
  96.                 lin(c+co,x)
  97.         END
  98.     END;
  99.     lin(5,x)
  100. END;
  101.  
  102. { this does the main job: load the copperlist }
  103. PROCEDURE CopperBuilder;
  104. VAR
  105.     j        :    Integer;
  106. BEGIN
  107.     { the copper list is automatically created the first time you 
  108.       start a copper instruction. No need to initialize by hand,
  109.       this is done by windowlib }
  110.     FOR j:=0 TO 255 DO BEGIN
  111.         CopperWait(screen,0,j);     { wait for the correct position }
  112.         CopperMove(screen,$180,cop[j])    { move the color in the background color register }
  113.     END;
  114.     CopperDone(screen)    { tell windowlib that we're done, load the copperlist }
  115. END;
  116.  
  117. { draw a horizontal pipe using the copper list }
  118. PROCEDURE Horizontal;
  119. VAR
  120.     r,g,b        :    Integer;
  121.     y,ym        :    Integer;
  122.     i        :    Integer;
  123.     c        :    Integer;
  124. BEGIN
  125.     Color(window,0);
  126.     r:=RangeRandom(6);
  127.     g:=RangeRandom(6);
  128.     b:=RangeRandom(6);
  129.     CASE s OF
  130.         1:    ym:=RangeRandom(254-30);
  131.         2:    ym:=RangeRandom(254-15);
  132.         3:    ym:=RangeRandom(254-60);
  133.     END;
  134.     y:=ym;
  135.     CASE s OF
  136.         1:    BEGIN
  137.                 FOR i:=0 TO 30 DO BEGIN
  138.                     c:=sub(b,i);
  139.                     c:=c+16*sub(g,i);
  140.                     c:=c+256*sub(r,i);
  141.                     IF c>0 THEN BEGIN
  142.                         cop[ym]:=c;
  143.                         ym:=ym+1;
  144.                     END
  145.                 END
  146.             END;
  147.         2:    BEGIN
  148.                 FOR i:=0 TO 15 DO BEGIN
  149.                     c:=sub(b,i*2);
  150.                     c:=c+16*sub(g,i*2);
  151.                     c:=c+256*sub(r,i*2);
  152.                     IF c>0 THEN BEGIN
  153.                         cop[ym]:=c;
  154.                         ym:=ym+1;
  155.                     END
  156.                 END
  157.             END;
  158.         3:    BEGIN
  159.                 FOR i:=0 TO 60 DO BEGIN
  160.                     c:=sub(b,i DIV 2);
  161.                     c:=c+16*sub(g,i DIV 2);
  162.                     c:=c+256*sub(r,i DIV 2);
  163.                     IF c>0 THEN BEGIN
  164.                         cop[ym]:=c;
  165.                         ym:=ym+1;
  166.                     END
  167.                 END
  168.             END;
  169.     END;
  170.     CopperBuilder; { build the copper list }
  171.     PBox(window,0,y,319,ym-1); {make it visible by showing the background color }
  172. END;
  173.  
  174.     
  175. BEGIN
  176.  
  177.     InitGraphics;
  178.     SelfSeed;
  179.  
  180.     screen:=OpenAScreen(0,0,320,256,6,MON_PAL OR MON_HAM,"CopperHammer");
  181.     IF screen<>NIL THEN BEGIN
  182.         SetColor(screen,0,0,0,0);
  183.         SetColor(screen,5,0,0,0);
  184.         window:=OpenScreenWindow(screen,0,0,320,256,$1900,NIL);
  185.         IF window<>NIL THEN BEGIN
  186.             BGColor(window,1);
  187.             ClearWindow(window);
  188.             BGColor(window,0);
  189.             REPEAT
  190.                 s:=RangeRandom(1)+1;
  191.                 CASE RangeRandom(3) OF
  192.                     0:
  193.                         Horizontal;
  194.                     1:
  195.                         Vertical;
  196.                     2:
  197.                         Vertical2;
  198.                     3:    BEGIN
  199.                         s:=s+1;
  200.                         Horizontal;
  201.                         END;
  202.                 END
  203.             UNTIL MouseButton(window);
  204.             CloseAWindow(window)
  205.         END;
  206.         CloseAScreen(screen);
  207.     END;
  208.  
  209.     ExitGraphics;
  210. END.